class Solution {
private:
    vector<char> con={'(',')'};
public:
    vector<string> res;
    string tmp;
    void dfs(int n,int left,int right){
        if(left>n||right>n)
            return;
        else if(left<right)
            return;
        else if(left==right&&left==n){
            res.emplace_back(tmp);
            return;
        }
        for(int i=0;i<2;i++){
            tmp.push_back(con[i]);
            i==0?left++:right++;
            dfs(n,left,right);
            tmp.pop_back();
            i==0?left--:right--;
        }
    }
    vector<string> generateParenthesis(int n) {
        dfs(n,0,0);
        return res;
    }
};
